package com.example.dormitory.service;

import com.example.dormitory.entity.*;
import com.example.dormitory.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class BuildService {

    @Autowired
    private BuildMapper buildMapper;

    public int create(Build build) {
        return buildMapper.create(build);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                buildMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return buildMapper.delete(id);
    }

    public int update(Build build) {
        return buildMapper.update(build);
    }

    public int updateSelective(Build build) {
        return buildMapper.updateSelective(build);
    }

    public PageInfo<Build> query(Build build) {
        if(build != null && build.getPage() != null){
            PageHelper.startPage(build.getPage(),build.getLimit());
        }
        return new PageInfo<Build>(buildMapper.query(build));
    }

    public Build detail(Integer id) {
        return buildMapper.detail(id);
    }

    public int count(Build build) {
        return buildMapper.count(build);
    }
}
